//
//  FourCell.m
//  WE
//
//  Created by 要帅气的生活 on 15/11/18.
//  Copyright © 2015年 UNOHACHA. All rights reserved.
//

#import "FourCell.h"
#import "Size.h"
#import "MicroMedicalViewController.h"
#import "DiseaseViewController.h"
#import "CommonDiseasesClickViewController.h"
@implementation FourCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        for (int i = 0; i < 8; i++) {
            UIButton *button  = [UIButton buttonWithType:UIButtonTypeSystem];
            if (i == 0) {
                button.frame = CGRectMake(10 , 10, 355/8*Width, 100*Height);
                [button setTitle:@"前列腺炎" forState:UIControlStateNormal];
                button.titleLabel.numberOfLines = 0;
                button.backgroundColor = [UIColor colorWithRed:204.0f/255.0f green:221.0f/255.0f blue:109.0f/255.0f alpha:1];
                button.tintColor = [UIColor whiteColor];
                button.titleLabel.font = [UIFont systemFontOfSize:15];
            }else if (i == 1){
                button.frame = CGRectMake(12+(375-20)/8*Width, 10, (375-20)/8*3*Width-2, 100*Height/2-1);
                [button setTitle:@"胃食管反流病" forState:UIControlStateNormal];
                button.tintColor = [UIColor whiteColor];
                button.titleLabel.font = [UIFont systemFontOfSize:15];button.backgroundColor = [UIColor colorWithRed:168.0f/255.0f green:204.0f/255.0f blue:176.0f/255.0f alpha:1];
            }else if (i == 2){
                button.frame = CGRectMake(11+(375-20)*Width/2 , 10, (375-20)*Width/16*3-3, 100*Height/2-1);
                [button setTitle:@"湿疹" forState:UIControlStateNormal];
                button.backgroundColor = [UIColor colorWithRed:204.0f/255.0f green:221.0f/255.0f blue:109.0f/255.0f alpha:1];
                button.tintColor = [UIColor whiteColor];
                button.titleLabel.font = [UIFont systemFontOfSize:15];
            }else if (i == 3){
                button.frame = CGRectMake(10+(375-20)*Width/16*11 , 10, (375-20)*Width/16*3-3, 100*Height/2-1);
                [button setTitle:@"胃炎" forState:UIControlStateNormal];
                button.backgroundColor = [UIColor colorWithRed:177.0f/255.0f green:206.0f/255.0f blue:222.0f/255.0f alpha:1];
                button.tintColor = [UIColor whiteColor];
                button.titleLabel.font = [UIFont systemFontOfSize:15];
            }else if (i == 4){
                button.frame = CGRectMake(9+(375-20)*Width/16*14 , 10, (375-20)*Width/8-1, 100*Height);
                [button setTitle:@"失眠" forState:UIControlStateNormal];
                button.backgroundColor = [UIColor colorWithRed:168.0f/255.0f green:204.0f/255.0f blue:176.0f/255.0f alpha:1];
                button.tintColor = [UIColor whiteColor];
                button.titleLabel.font = [UIFont systemFontOfSize:15];
            }else if (i == 5){
                button.frame = CGRectMake(12+(375-20)*Width/8 , 100*Height/2+11, (375-20)*Width/16*3-3, 100*Height/2-1);
                [button setTitle:@"鼻炎" forState:UIControlStateNormal];
                button.backgroundColor = [UIColor colorWithRed:177.0f/255.0f green:206.0f/255.0f blue:222.0f/255.0f alpha:1];
                button.tintColor = [UIColor whiteColor];
                button.titleLabel.font = [UIFont systemFontOfSize:15];
            }else if (i == 6){
                button.frame = CGRectMake(11+(375-20)*Width/16*5 , 100*Height/2+11, (375-20)*Width/8*3-3, 100*Height/2-1);
                [button setTitle:@"幽门螺杆菌感" forState:UIControlStateNormal];
                button.backgroundColor = [UIColor colorWithRed:253.0f/255.0f green:153.0f/255.0f blue:75.0f/255.0f alpha:1];
                button.tintColor = [UIColor whiteColor];
                button.titleLabel.font = [UIFont systemFontOfSize:15];
            }else if (i == 7){
                button.frame = CGRectMake(10+(375-20)*Width/16*11 , 100*Height/2+11, (375-20)*Width/16*3-3, 100*Height/2-1);
                [button setTitle:@"牙周炎" forState:UIControlStateNormal];
                button.backgroundColor = [UIColor colorWithRed:177.0f/255.0f green:180.0f/255.0f blue:145.0f/255.0f alpha:1];
                button.tintColor = [UIColor whiteColor];
                button.titleLabel.font = [UIFont systemFontOfSize:15];
            }
            button.tag = 1000+i;
            [button addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:button];
        }
    }
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    return self;
}
-(void)button:(UIButton *)button
{
    NSLog(@"%ld   %@",button.tag,button.titleLabel.text);
    
    if (button.tag == 1001 || button.tag == 1006) {
        CommonDiseasesClickViewController *common = [CommonDiseasesClickViewController new];
        common.str = button.titleLabel.text;
        common.view.backgroundColor = [UIColor whiteColor];
        [[self viewController].navigationController pushViewController:common animated:YES];
        
    }else{
        DiseaseViewController *disease = [DiseaseViewController new];
        disease.string = button.titleLabel.text;
        disease.view.backgroundColor = [UIColor whiteColor];
        [[self viewController].navigationController pushViewController:disease animated:YES];
    }
    
    
}

- (UIViewController *)viewController{
    for (UIView *next = [self superview]; next; next = next.superview) {
        UIResponder *nextResponder = [next nextResponder];
        if ([nextResponder isKindOfClass:[UIViewController class]]) {
            return (UIViewController *)nextResponder;
        }
    }
    return nil;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
